﻿using HCD.Web.Authorizer;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Partner.Utility;
using System;
using System.Linq;
using System.Threading.Tasks;

namespace HCD.Web.Controllers
{
    public class HomeController : EnterpriseControllerBase
    {
        /// <summary>
        /// 身份验证失败跳转
        /// </summary>
        /// <returns></returns>
        [AllowAnonymous]
        public ActionResult Error()
        {
            return View();
        }
        /// <summary>
        /// 视图 /Home/Index
        /// </summary>
        /// <returns></returns>
        [AllowAnonymous]
        public ActionResult Index()
        {
            return View();
        }
        /// <summary>
        /// 临时token
        /// </summary>
        /// <returns></returns>
        [AllowAnonymous]
        public ActionResult CreateToken()
        {
            var auth = new AuthModel { Id = 1, EmpNo = "000000", UserName = "admin", PhoneNumber = null, Name = "鲲鹏主席", IsAdmin = false, Exp = DateTime.Now.AddDays(1), TenantID = null };
            var token = JWTUtil.GenerateToken(auth);
            //写入client，swagger就不用再传token了
            HttpContext.Response.Cookies.Append("ck_token", token);
            //api 请求时，需要加入header Headers["token"]
            return Json(token);
        }
    }
}
